package com.ruoyi.web.controller.lipin;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.lipin.domain.LpProduct;
import com.ruoyi.lipin.domain.LpStrategy;
import com.ruoyi.lipin.domain.vo.LpProductVo;
import com.ruoyi.lipin.domain.vo.LpStrategyVo;
import com.ruoyi.lipin.service.ILpCollectionService;
import com.ruoyi.lipin.service.ILpProductService;
import com.ruoyi.lipin.service.ILpStrategyService;
import com.ruoyi.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 小程序业务接口
 *
 * @author YourName
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/miniProgram")
public class MiniProgramLiPinApiController extends BaseController {

    private final ILpProductService productService;
    private final ILpStrategyService strategyService;
    private final ILpCollectionService collectionService;
    //private final ILpFeedbackService feedbackService;
    private final ISysUserService userService;

    /**
     * 获取首页推荐数据
     */
    @GetMapping("/home")
    public R<Map<String, Object>> getHomeData() {
        Map<String, Object> result = new HashMap<>();
        result.put("hotProducts", productService.getHotProducts(10));
        //result.put("newStrategies", strategyService.getNewStrategies(5));
        return R.ok(result);
    }

    /**
     * 商品筛选接口
     */
    @PostMapping("/filterProducts")
    public R<TableDataInfo<LpProduct>> filterProducts(@RequestBody Map<String, Object> filterParams, PageQuery pageQuery) {
        return R.ok(productService.filterProducts(filterParams, pageQuery));
    }

    /**
     * 获取商品详情
     *
     * @param productId 商品ID
     */
    @GetMapping("/product/{productId}")
    public R<LpProductVo> getProductDetail(@PathVariable Long productId) {
        return R.ok(productService.queryById(productId));
    }

    /**
     * 获取攻略列表
     */
    @GetMapping("/strategies")
    public TableDataInfo<LpStrategy> getStrategies(LpStrategy strategy,PageQuery pageQuery) {
        return strategyService.selectPageStrategyList(strategy,pageQuery);
    }

    /**
     * 获取攻略详情
     *
     * @param strategyId 攻略ID
     */
    @GetMapping("/strategy/{strategyId}")
    public R<LpStrategyVo> getStrategyDetail(@PathVariable Long strategyId) {
        return R.ok(strategyService.queryById(strategyId));
    }

//    /**
//     * 新增收藏
//     */
//    @SaCheckPermission("miniProgram:collection:add")
//    @Log(title = "用户收藏", businessType = BusinessType.INSERT)
//    @PostMapping("/collection")
//    public R<Void> addCollection(@RequestBody LpCollectionVo collectionVo) {
//        return toAjax(collectionService.addCollection(collectionVo));
//    }
//
//    /**
//     * 删除收藏
//     *
//     * @param collectionId 收藏ID
//     */
//    @SaCheckPermission("miniProgram:collection:remove")
//    @Log(title = "收藏管理", businessType = BusinessType.DELETE)
//    @DeleteMapping("/collection/{collectionId}")
//    public R<Void> removeCollection(@PathVariable Long collectionId) {
//        return toAjax(collectionService.removeCollection(collectionId));
//    }
//
//    /**
//     * 获取用户收藏列表
//     *
//     * @param userId 用户ID
//     */
//    @GetMapping("/collections/{userId}")
//    public R<List<CollectionVo>> getUserCollections(@PathVariable Long userId, PageQuery pageQuery) {
//        return R.ok(collectionService.getUserCollections(userId, pageQuery));
//    }
//
//    /**
//     * 提交反馈
//     */
//    @SaCheckPermission("miniProgram:feedback:add")
//    @Log(title = "反馈管理", businessType = BusinessType.INSERT)
//    @PostMapping("/feedback")
//    public R<Void> submitFeedback(@RequestBody FeedbackVo feedbackVo) {
//        return toAjax(feedbackService.submitFeedback(feedbackVo));
//    }
//
//    /**
//     * 获取用户信息
//     *
//     * @param userId 用户ID
//     */
//    @GetMapping("/user/{userId}")
//    public R<Map<String, Object>> getUserInfo(@PathVariable Long userId) {
//        Map<String, Object> result = new HashMap<>();
//        result.put("user", userService.getUserInfo(userId));
//        return R.ok(result);
//    }
//
//    /**
//     * 更新用户信息
//     */
//    @SaCheckPermission("miniProgram:user:edit")
//    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
//    @PutMapping("/user")
//    public R<Void> updateUserInfo(@RequestBody Map<String, Object> userInfo) {
//        return toAjax(userService.updateUserInfo(userInfo));
//    }
}
